import java.util.Scanner;

public class Test01 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int a,b,c ,d;
        a = scanner.nextInt(); b = scanner.nextInt() ; c = scanner.nextInt(); d = scanner.nextInt();
        int[] times = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            times[i] = scanner.nextInt();
        }
        int[] dp = new int[n+1];
        dp[0] = 0;
        for (int i = 1; i <= n; i++) {
            int sDay = times[i] * 1;
            dp[i] = dp[i-1] + sDay;

            dp[i] = Math.min(dp[i] , dp[i - 1]+a);
            if(i >= 30){
                dp[i] = Math.min(dp[i] , dp[i-30] +b);
            }else{
                dp[i] = Math.min(dp[i] , b);
            }
            //年卡
            if( i >= 365){
                dp[i] = Math.min(dp[i] , dp[i - 365]+c);
            }else{
                dp[i] = Math.min(dp[i] , c);
            }
            //十年卡
            if(i >=3650){
                dp[i] = Math.min(dp[i] , dp[i - 3650] + d);
            }else{
                dp[i] = Math.min(dp[i],d);
            }

        }
        System.out.println(dp[n]);
    }
}
